
package edu.tongji.jiaowu.dao.jdbc;
 
import java.util.List;

import edu.tongji.jiaowu.dao.ReexaminationStudentDao;
import com.tongji.quickCRUDQ.define.Row;
import com.tongji.quickCRUDQ.model.CommonBean;
import com.tongji.quickCRUDQ.dao.jdbc.BaseDaoJdbc;

public class ReexaminationStudentDaoJdbc extends BaseDaoJdbc implements ReexaminationStudentDao {
	String tableName="T_REEXAMINATION_STUDENT";
	String beanName="reexaminationStudent";
	
	public CommonBean createReexaminationStudent(){
		CommonBean reexaminationStudents=this.createBean(tableName,beanName);
                return reexaminationStudents;		
	}
	
/*
	public CommonBean findReexaminationStudents(String refid) {
		CommonBean reexaminationStudents=this.createReexaminationStudent();
		String sql="select * from T_REEXAMINATION_STUDENT where refid=?";
		List data=this.getCommonDao().select(sql,new String[]{refid});
		reexaminationStudents.addData(data);
                return reexaminationStudents;
       }
*/
	public CommonBean findReexaminationStudentById(String id) {
		CommonBean reexaminationStudents=this.createReexaminationStudent();
		String sql="select * from T_REEXAMINATION_STUDENT where id=?";
		List data=this.getCommonDao().select(sql,new String[]{id});
		reexaminationStudents.addData(data);
    return reexaminationStudents;
  }
  
	public CommonBean findAllReexaminationStudents() {
		CommonBean reexaminationStudents=this.createReexaminationStudent();
		String sql="select * from T_REEXAMINATION_STUDENT ";
		List data=this.getCommonDao().select(sql,new String[]{});
		reexaminationStudents.addData(data);
    return reexaminationStudents;
  }
	public void insertReexaminationStudent(CommonBean reexaminationStudentBean){
		List data=reexaminationStudentBean.getData();
		Row row=this.getRow(tableName);
		this.getCommonDao().templateBatchInsert(row,data,this.getIdGenerator());
	}
	public void updateReexaminationStudent(CommonBean reexaminationStudentBean){
		List data=reexaminationStudentBean.getData();
		Row row=this.getRow(tableName);
		this.getCommonDao().templateBatchUpdate(row,data);
	}

	public void loadReexamStudents(String reexamYear, String reexamSemester) {
		String delSql="delete from T_REEXAMINATION_STUDENT where school_year=? and school_semester=?";
		String insertSql=
			"INSERT INTO T_REEXAMINATION_STUDENT(ID,SCHOOL_YEAR,SCHOOL_SEMESTER,COURSE_NO,CLASS_NO,COURSE_NAME,\n" +
			"STUDENT_NO,STUDENT_NAME,GRADE,COLLEGE_DEPARTMENT,COLLEGE_NAME,MAJOR,MAJOR_NAME,score,score_nature,SCORE_FORMAT,SCORE_ID,COURSE_ID)\n" + 
			"select dbo.get_seq(),school_year,school_semester,COURSE_NO,CLASS_NO,COURSE_NAME,\n" + 
			"STUDENT_NO,STUDENT_NAME,GRADE,COLLEGE_DEPARTMENT,COLLEGE_NAME,MAJOR,MAJOR_NAME,score,score_nature,SCORE_FORMAT,\n" + 
			"id score_id,refid course_id\n" + 
			"from V_REEXAMINATION_STUDENTS\n" + 
			"where school_year=? and school_semester=?";
		String[] params=new String[]{reexamYear,reexamSemester};
		getCommonDao().updateRecord(delSql, params);
		getCommonDao().updateRecord(insertSql, params);

	}
}

